import java.awt.Color;
import java.awt.Font;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.UIManager;

import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;


//VS4E -- DO NOT REMOVE THIS LINE!
public class WinnerFrame extends JFrame {

	private JLabel winnerToken;
	private JLabel background;
	private JTextField winnerNameTextField;
	private JTextField winnerMoneyTextField;
	
	Player orderedPlayer[] = new Player[8];
	int counter;
	
	private static final long serialVersionUID = 1L;
	
	private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
	public WinnerFrame() {
		initComponents();
	}
	
	private void initComponents() {
		setTitle("Monopoly");
		setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/images/icon.png")));
		setResizable(false);
		setAlwaysOnTop(true);
		setLayout(new GroupLayout());
		
		add(winnerToken(), new Constraints(new Leading(0, 10, 10), new Leading(65, 10, 10)));
		add(winnerNameTextField(), new Constraints(new Leading(100, 10, 10), new Leading(80, 10, 10)));
		add(winnerMoneyTextField(), new Constraints(new Leading(100, 10, 10), new Leading(110, 10, 10)));
		add(background(), new Constraints(new Leading(0, 10, 10), new Leading(0, 10, 10)));
		
		setSize(240, 190);
		setDefaultCloseOperation(WinnerFrame.EXIT_ON_CLOSE);
		getContentPane().setPreferredSize(getSize());
		pack();
		setLocationRelativeTo(null);
		setVisible(false);
	}
	
	private JLabel background() {
		if (background == null) {
			background = new JLabel();
			background.setIcon(new ImageIcon(getClass().getResource("/images/winner.jpg")));
		}
		return background;
	}
	private JLabel winnerToken() {
		if (winnerToken == null) {
			winnerToken = new JLabel();
			winnerToken.setIcon(new ImageIcon(getClass().getResource("/images/tokenDefault_b.png")));
		}
		return winnerToken;
	}

	private JTextField winnerMoneyTextField() {
		if (winnerMoneyTextField == null) {
			winnerMoneyTextField = new JTextField();
			winnerMoneyTextField.setEditable(false);
			winnerMoneyTextField.setFont(new Font("Eras Light ITC", Font.PLAIN, 14));
			winnerMoneyTextField.setOpaque(false);
			winnerMoneyTextField.setAutoscrolls(false);
			winnerMoneyTextField.setBorder(null);
			winnerMoneyTextField.setText("$ 15000000");
			winnerMoneyTextField.setEnabled(false);
			winnerMoneyTextField.setDisabledTextColor(Color.white);
		}
		return winnerMoneyTextField;
	}

	private JTextField winnerNameTextField() {
		if (winnerNameTextField == null) {
			winnerNameTextField = new JTextField();
			winnerNameTextField.setEditable(false);
			winnerNameTextField.setFont(new Font("Eras Light ITC", Font.PLAIN, 22));
			winnerNameTextField.setOpaque(false);
			winnerNameTextField.setAutoscrolls(false);
			winnerNameTextField.setBorder(null);
			winnerNameTextField.setEnabled(false);
			winnerNameTextField.setText("Anonymous");
			winnerNameTextField.setDisabledTextColor(Color.white);
		}
		return winnerNameTextField;
	}
	
	public void loadVisuals(){
		winnerToken.setIcon(new ImageIcon(getClass().getResource("/images/token"+orderedPlayer[counter].getAssignedLabel()+"_b.png")));
		winnerNameTextField.setText(orderedPlayer[counter].getName());
		winnerMoneyTextField.setText("$ "+orderedPlayer[counter].getMoney());
	}
	
	@SuppressWarnings("unused")
	private static void installLnF() {
		try {
			String lnfClassname = PREFERRED_LOOK_AND_FEEL;
			if (lnfClassname == null)
				lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
			UIManager.setLookAndFeel(lnfClassname);
		} catch (Exception e) {
			System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL
					+ " on this platform:" + e.getMessage());
		}
	}
	
}